package com.example.myapplication3.persenter;

import android.view.View;

import com.example.myapplication3.bean.Beijing;
import com.example.myapplication3.bean.Student1;
import com.example.myapplication3.bean.Student2;
import com.example.myapplication3.bean.Student3;
import com.example.myapplication3.bean.Student4;
import com.example.myapplication3.interfaces.Callback;
import com.example.myapplication3.interfaces.IHome;
import com.example.myapplication3.module.HomeModel;

import java.util.Map;

public class HomePersenter implements IHome.Persenter {

    private final IHome.View view;
    private final HomeModel homeModel;

    public HomePersenter(IHome.View view){
        this.view = view;
        homeModel = new HomeModel();
    }

    @Override
    public void getCity1() {
      view.loading(View.VISIBLE);
        homeModel.getCity(new Callback() {
            @Override
            public void fail(String msg) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.tips(msg);
                }
            }

            @Override
            public void success(Object object) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.getStudent1((Student1) object);
                }
            }
        });
    }

    @Override
    public void getCity2(Map<String, String> map) {
        view.loading(View.VISIBLE);
            homeModel.getCity2(map, new Callback() {
                @Override
                public void fail(String msg) {
                    if(view!=null){
                        view.loading(View.GONE);
                        view.tips(msg);
                    }
                }

                @Override
                public void success(Object object) {
                    if(view!=null){
                        view.loading(View.GONE);
                        view.getStudent2((Student2) object);
                    }
                }
            });
    }

    @Override
    public void getCity3(Map<String, String> map) {
        homeModel.getCity3(map, new Callback() {
            @Override
            public void fail(String msg) {
                view.loading(View.VISIBLE);
                if(view!=null){
                    view.loading(View.GONE);
                    view.tips(msg);
                }
            }

            @Override
            public void success(Object object) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.getStudent3((Student3) object);
                }
            }
        });
    }

    @Override
    public void getCity4(Map<String, String> map) {
        view.loading(View.VISIBLE);
        homeModel.getCity4(map, new Callback() {
            @Override
            public void fail(String msg) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.tips(msg);
                }
            }

            @Override
            public void success(Object object) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.getStudent4((Student4) object);
                }
            }
        });
    }
    @Override
    public void getCity5() {
        view.loading(View.VISIBLE);
        homeModel.getCity5(new Callback() {
            @Override
            public void fail(String msg) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.tips(msg);
                }
            }

            @Override
            public void success(Object object) {
                if(view!=null){
                    view.loading(View.GONE);
                    view.getStudent5((Beijing) object);
                }
            }
        });
    }
}


